var myChart = null,
    myCharts = [];

//确定容器情况
window.__currentLayout__ = "NxM";
window.__currentTheme__ = "vintage";
window.__layoutCustomized__ = true;
window.__layoutHeight__ = ["33.33%", "33.33%", "33.33%"];
window.__layoutWidth__ = ["50%", "50%"];

$(document).ready(function () {
    debugger;
    if (window.__currentLayout__ && window.__layoutCustomized__)
        var e = window.__layoutWidth__.length * window.__layoutHeight__.length;
    else
        var e = 0;
    run_create(e)
    run_option();
});

//设置容器
function run_create(t) {
    if (t) {
        myChart && myChart.dispose(),
            myChart = null,
            $("#chart-panel").html("");
        for (var e = 0; e < myCharts.length; ++e) myCharts[e] && myCharts[e].dispose();
        myCharts = [];
        var n = t;
        if (window.__currentLayout__ && window.__layoutCustomized__) n = window.__layoutWidth__.length * window.__layoutHeight__.length;
        else if (window.__layoutWidth__ = [], window.__layoutHeight__ = [], "1xN" === window.__currentLayout__) {
            for (var e = 0; e < n; ++e) window.__layoutWidth__.push(100 / n + "%");
            window.__layoutHeight__.push("100%")
        } else if ("NxM" === window.__currentLayout__) {
            for (var i = Math.ceil(Math.sqrt(n)), e = 0; e < i; ++e) window.__layoutWidth__.push(100 / i + "%");
            for (var o = Math.ceil(n / i), e = 0; e < o; ++e) window.__layoutHeight__.push(100 / o + "%")
        } else {
            window.__layoutWidth__.push("100%");
            for (var e = 0; e < n; ++e) window.__layoutHeight__.push(100 / n + "%")
        }
        t < n && console.warn("部分图表没有对应的布局项，因而未被显示。");
        for (var a = 0,
            r = 0; r < window.__layoutHeight__.length; ++r) for (var s = 0; s < window.__layoutWidth__.length && !(a >= t); ++s) {
                var h = $('<div style="width: ' + window.__layoutWidth__[s] + "; height: " + window.__layoutHeight__[r] + '; float: left; display: inline-block"></div>');
                $("#chart-panel").append(h);
                var _ei = echarts.init(h[0]);
                myCharts.push(_ei),
                    ++a
            }
    } else {
        myChart && myChart.dispose(),
            myChart = echarts.init($("#chart-panel")[0]),
            myCharts = [myChart];
    }
}

function run_option() {
    debugger;
    if (typeof (option) != "undefined" && myChart != null)
        myChart.setOption(option, !0);
    else if (options) {
        for (var i = 0; i < myCharts.length; ++i) options[i] && myCharts[i].setOption(options[i])
    }
}